package com.fullsail.services
{
	import com.fullsail.events.StateServiceEvent;
	import com.fullsail.vo.StateVO;
	
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.mxml.HTTPService;
	import mx.collections.ArrayCollection;
	
	[Event(name="loaded", type="com.fullsail.events.StateServiceEvent")]
	public class StateService extends HTTPService
	{
		private var _state:Array;
		
		public function StateService(rootURL:String=null,destination:String=null)
		{
			super(rootURL, destination);
			this.addEventListener(ResultEvent.RESULT, onResult);
		}
		
		private function onResult(event:ResultEvent):void
		{
			_state = [];
			var ar:Array = ArrayCollection(event.result.states.state).source;
			for each(var obj:Object in ar)
			{
				var go:StateVO = new StateVO();
				go.abbrev = obj.abbrev;
				go.name = obj.name;
				
				_state.push(go);
			}
			
			var evt:StateServiceEvent = new StateServiceEvent(StateServiceEvent.LOADED);
			evt.states = _state;
			this.dispatchEvent(evt);
		}

	}
}